﻿Pui.space = {
    init: function() {
		this.emotion();
		this.emotions();
		this.VideoWelter();
        Pui.header.init();
        Pui.searching.init();
		if(document.getElementById('SpaceColumn')){
			 this.writeMenu();
		}
    },
    writeMenu: function() {
        var id = $('body').attr('id');
        var s = '';
        s += '<div class="l_fix"><div class="r_fix">';
        s += '<div>';
        s += (id == 'SpaceHome') ? '<strong>主页</strong> |': '<a href="http://home.pomoho.com/' + _space_user.username + '.shtml">主页</a> |';
        s += (id == 'SpaceColumn') ? '<strong>视频</strong> |': '<a href="http://home.pomoho.com/' + _space_user.username + '/videolist">视频</a> |';
        s += (id == 'SpaceAlbum' || id == 'newSpaceAlbum') ? '<strong>图片</strong> |': '<a href="http://www.pomoho.com/album/' + _space_user.username + '">图片</a> |';
        s += (id == 'SpaceBlog') ? '<strong>博文</strong> |': '<a href="http://home.pomoho.com/' + _space_user.username + '/blog">博文</a> |';
        s += (id == 'SpaceDoing') ? '<strong>微博</strong> |': '<a href="http://home.pomoho.com/' + _space_user.username + '/doing" rel="平时都在干啥？">微博</a> |';
        s += (id == 'SpaceFriend') ? '<strong>好友</strong> |': '<a href="http://home.pomoho.com/' + _space_user.username + '/friend">好友</a> |';
        s += (id == 'SpaceFans') ? '<strong>粉丝</strong> |': '<a href="http://home.pomoho.com/' + _space_user.username + '/fans">粉丝</a> |';
        s += (id == 'SpaceGuestBook') ? '<strong>留言</strong> |': '<a href="http://home.pomoho.com/' + _space_user.username + '/guestbook">留言</a> |';
        s += (id == 'SpaceRss') ? '<strong>订阅</strong> |': '<a href="http://home.pomoho.com/' + _space_user.username + '/subscribtion">订阅</a> |';
        s += (id == 'SpaceFavorite') ? '<strong>收藏</strong> |': '<a href="http://home.pomoho.com/' + _space_user.username + '/favorite">收藏</a> |';
        s += '</div>';
        s += '<p class="is_login"><a href="http://home.pomoho.com/' + _space_user.username + '/doing">写记事本</a></p>';
        s += '</div></div>';
        $(s).appendTo($('#Menu'));
        _is_login = false;
        var n = Pui.cookie('LoginInfo');
        if (n) {
            var arr = n.split('$***$');
            _user = {
                uid: arr[0].replace('LoginInfo=', ''),
                nick: arr[1],
                spacename: arr[2],
                username: arr[3],
                newmsg: 0
            };
            _is_login = true;
            if (typeof(_user.uid) != 'undefined' && _user.uid == _space_user.uid) {
                $('.is_login').css('display', 'inline');
            }
        }
        if (!$('body').hasClass('custom')) {
            switch (_space_user.username) {
            case 'yuepaiyuegao':
                var link_create = document.createElement('a');
                link_create.target = '_blank';
                link_create.href = 'http://www.yuepaiyuegao.com';
                $(link_create).css({
                    'position': 'absolute',
                    'width': '680px',
                    'height': '300px',
                    'display': 'block',
                    'left': 0,
                    'top': 0
                }).appendTo('#SpaceTitle');
                break;
            case 'zhongguodili':
                var w = $('body').width() - $('.body_btm_fix').width();
                $('<div class="color_pack1"></div>').prependTo('body');
                $('<div class="color_pack2"></div>').prependTo('.body_btm_fix');
				$('<div class="side_block"></div>').css({
                    'width': (w - 6) / 2,
                    'right': -((w - 6) / 2 + 4)
                }).prependTo('.body_btm_fix');
                break;
            case 'titan24':
                link_create.href = 'http://www.titan24.com';
                $(link_create).css({
                    'position': 'absolute',
                    'width': '310px',
                    'height': '86px',
                    'display': 'block',
                    'left': '310px',
                    'top': '120px'
                }).appendTo('#SpaceTitle');
                break;
            case '9158com':
                $('<style type="text/css">.adlink{position:absolute;left:620px;font-size:16px;font-weight:bold;color:#616c70 !important;}#Space .adlink:hover,#Space .link4:hover{color:#ff7800 !important;}.link1{top:140px;}.link2{top:170px;}.link3{top:200px;}#Space .link4{top:240px;left:600px;color:blue;}</style>').appendTo('head');
                $('<a class="adlink link1" href="http://www.paopao8.cn" target="_blank">泡泡吧</a>').add('<a class="adlink link2" href="http://www.91555.com/jjd" target="_blank">斗地主</a>').add('<a class="adlink link3" href="http://www.91555.com/zhuanti/kill" target="_blank">杀人游戏</a>').add('<span class="adlink" style="font-size:12px;top:276px;left:480px">点击下载：<a class="link4" href="http://tg.01lm.com/9158chat_bmh.exe" target="_blank">万人在线K歌</a></span>').appendTo('#SpaceTitle');
            }
        }
    },
    logInfo: function() {
        $('<div id="top_Nav"><div class="out" id="L"><ul><li class="s1 log"><a title="" href="javascript:Pui.header.loginfo2(Pui.header.loginfo2_callback);">登录</a></li><li class="s2 reg"><a href="http://www.pomoho.com/ui/reg.aspx" target="_blank">注册</a></li><li class="s2"><a target="_blank" href="http://bbs.pomoho.com">论坛</a></li></ul></div></div><script type="text/javascript">Pui.header.init();</script>').prependTo('#SpaceTitle');
    },
    emotion: function(what) {
        var emotionID = 1;
        $(what + ' .emotion').find('.l').click(function() {
            if (emotionID >= 2) {
                $('#emotionBox').animate({
                    left: -(450 * (emotionID - 2))
                },
                1000);
                if (emotionID == 2) {
                    $(what + ' .l').removeClass('l_b').attr('title', '左边没有了');
                } else if (emotionID == 4) {
                    $(what + ' .r').addClass('r_b').attr('title', '向右翻');
                }
                emotionID--;
            }
            this.blur();
            return false;
        }).end().find('.r').click(function() {
            if (emotionID <= 3) {
                $('#emotionBox').animate({
                    left: -(450 * emotionID)
                },
                1000);
                if (emotionID == 1) {
                    $(what + ' .l').addClass('l_b').attr('title', '向左翻');
                } else if (emotionID == 3) {
                    $(what + ' .r').removeClass('r_b').attr('title', '右边没有了');
                }
                emotionID++;
            }
            this.blur();
            return false;
        }).end().find('div a').each(function() {
            $(this).click(function() {
                var tmp = $(what + ' textarea').val() + $(this).find('img').attr('src').replace(/.+\/(em\d+)\.gif/g, '[$1]');
                $(what + ' textarea').val(tmp);
                return false;
            });
        });
    },
    emotionWR: function(what) {
        var s = '';
        s += '<div style="position:relative;width:450px;height:60px;overflow:hidden;margin:5px auto;"><div id="emotionBox" style="position:absolute;left:0;top:0;width:1800px;">';
        var l = 'http://static.pomoho.com/images/em/';
        var alt = ['黑星打', '大', '泡', '蹦', '继续', '狂', '黑星殴', '吹', '捅', '被殴', '飞', '嘘', '赖', '顶', '变', '滚球', '生', '膜拜', '转', '口', 'KI', '鬼', '抓狂', '扯', '流', '闭嘴', 'HI', '可爱', '摇', '躲', '多', '吉'];
        for (var i = 1; i <= 4; i++) {
            s += '<div style="width:450px;float:left;text-align:center;">';
            for (var j = (i - 1) * 8 + 1; j <= i * 8; j++) {
                if (j <= 32) {
                    s += '<a href="" title="' + alt[j - 1] + '" style="margin:0 1px;"><img src="' + l + 'em' + j + '.gif" height="50" width="50" /></a>';
                }
            }
            s += '</div>';
        }
        s += '</div></div>';
        s += '<a href="" class="l" title="左边没有了">向左翻</a><a href="" class="r r_b" title="向右翻">向右翻</a>';
        $(s).appendTo($('.emotion'));
        this.emotion(what);
        this.commentLoad();
    },
    commentLoad: function() {
        $('<div class="loading">评论加载中...</div>').insertBefore($('.commentAdd'));
        var sh = ("innerHeight" in window )?window.innerHeight:document.documentElement.offsetHeight;
        var comm = $('#Comment')[0];
        var commentTop = comm.offsetTop + 100;
        setTimeout(function(){
        var reviewNum=parseInt($('#video_'+flvid+'_999').find('.c_review span').html());
        if (commentTop < sh && reviewNum>0) { 
	        Pui.ajaxLoad('GET', 'http://home.pomoho.com/do/interfaces/getvideoreview.aspx', 'videoid=' + flvid + '&r=' + Math.random(), 'html', '',
		        function() {
			        $('#Comment').prepend(_getDATA);
		        }
	        );
        } else if (commentTop >= sh && reviewNum>0) { (function g() {
	        if (document.documentElement.scrollTop + sh >= commentTop) {
		        Pui.ajaxLoad('GET', 'http://home.pomoho.com/do/interfaces/getvideoreview.aspx', 'videoid=' + flvid + '&r=' + Math.random(), 'html', '',
			        function() {
				       $('#Comment').prepend(_getDATA);
			        }
		         );
	        } else {setTimeout(function() {g();},2000);}
            })();
        }	
        },5000);
    },
    commentReply: function(what) {
        this.SetValidCodeImg(what);
        var _self = this;
        $('#post_content').bind('focus',
        function() {
            _self.CodeImgLoader()
        });
        $(what + ' input[@type=submit]').click(function() {
            textarea = $(what + ' textarea');
            if ($.trim(textarea.val()) == '') {
                alert('留言内容不可为空！');
                textarea.focus();
                return;
            }
            var sValidCode = "";
            if (document.getElementById("tb_validcode") != null) {
                sValidCode = document.getElementById("tb_validcode").value;
                if ($.trim(sValidCode) == '') {
                    alert('验证码不可为空！');
                    return;
                }
            }
            var content = textarea.val().replace("<", "&lt;").replace(">", "&gt;").replace("&", "<--@@-@@-->");
//            允许匿名访问
//            if (_is_login) {
                switch (what) {
                case '#Comment':
                    Pui.loadScript(baseurl + "/video/dealajaxdata.aspx?itype=1&imdbid=" + flvid + "&content=" + escape(content) + "&validcode=" + sValidCode, {
                        random: true
                    });
                    break;
                case '#GuestBook':
                    Pui.loadScript(baseurl + "/space/personjs.aspx?dotype=4&userid=" + _space_user.uid + "&content=" + escape(content) + "&validcode=" + sValidCode, {
                        random: true
                    });
                }
                var ct = Pui.ui.pos.elementTop(document.getElementById(what.slice(1)));
                window.scrollTo(0, ct - 30);
                this.blur();
                setTimeout("Pui.space.commentReplyFill()", 1000);
                _self.GetValidCodeImg();
                return false;
//            } else {
//                flag = 6;
//                Pui.header.loginfo();
//            }
        });
    },
    commentJudge: function() {
        var sValidCode = document.getElementById("tb_validcode").value;
        if (document.getElementById('Comment')) {
            var content = $('#Comment textarea').val().replace("<", "&lt;").replace(">", "&gt;").replace("&", "<--@@-@@-->");
            Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=1&imdbid=" + flvid + "&content=" + escape(content) + "&validcode=" + sValidCode, {
                random: true
            });
        } else if (document.getElementById('GuestBook')) {
            var content = $('#GuestBook textarea').val().replace("<", "&lt;").replace(">", "&gt;").replace("&", "<--@@-@@-->");
            Pui.loadScript(baseurl + "/space/personjs.aspx?dotype=4&userid=" + _space_user.uid + "&content=" + escape(content) + "&validcode=" + sValidCode, {
                random: true
            })
        }
        setTimeout("Pui.space.commentReplyFill()", 1000);
        Pui.space.GetValidCodeImg();
        Pui.header.closeDiv();
    },
    hideComment: function(num) {
        if (String(window.location).match(/http:\/\/home.*/)) {
            $('#Comment .mDocument').filter(':gt(19)').hide();
        } else {
            $('#Comment .mDocument').filter(':gt(19)').hide();
        }
        $('#Comment h3 span.count').html(20);
    },
    commentQuote: function(bid) {
        var re_q_txt = document.getElementById("re_q_" + bid).value;
        document.getElementById("post_content").value = "[quote]" + re_q_txt + "[/quote]";
        $('#Comment textarea').focus();
    },
    commentReplyFill: function() {
        var c = textarea.val().replace(/\[em(\d+)\]/g, "<img src='http://static.pomoho.com/images/em/em$1.gif' />");
        var u = _is_login ? '<a href="javascript:;">' + _user.nick + '</a>': '游客';
        var s = '';
        var mdL = $('#Comment .cl').length;
        var icount = $('#CM h3 .title span').text() ? $('#CM h3 .title span').text() : 0;
        icount = parseInt(icount);
        var vtitle = $.trim($('title').html());
        var s_href = 'http://video.pomoho.com/review.aspx?flvid=' + flvid + '&icount=' + (icount + 1) + '&title=' + vtitle + '&uid=' + _space_user.uid;
        if (mdL) {
            s += '<div class="mDocument" style="_width:100%;">';
            s += ' <div class="photo"><img src="http://static.pomoho.com/static/images/photo_68.gif" alt="" /></div>';
            s += ' <div class="detail">';
            s += '  <span class="n_user">' + u + '</span>';
            s += '  <p class="text">' + c + '</p>';
            s += ' </div>';
            s += ' <div class="handle">';
            s += '  <span class="t_release">' + Pui.ui.gettime() + '</span>';
            s += ' </div>';
            s += '</div>';
            $('#Comment .cl').prepend(s).fadeTo('slow', 1);
            $('#CM h3 .title span').text(icount + 1).parents('h3').find('.more a').attr('href', s_href);
        } else {
            s += '<h3><span class="title">网友评论（共<span>' + (icount + 1) + '</span>条）</span><span class="more"><a target="_blank" href="' + s_href + '">更多</a></span></h3>';
            s += '<div class="cl showblock"><div class="mDocument">';
            s += ' <div class="photo"><img src="http://static.pomoho.com/static/images/photo_68.gif" alt="" /></div>';
            s += ' <div class="detail">';
            s += '  <span class="n_user">' + u + '</span>';
            s += '  <p class="text">' + c + '</p>';
            s += ' </div>';
            s += ' <div class="handle">';
            s += '  <span class="t_release">' + Pui.ui.gettime() + '</span>';
            s += ' </div>';
            s += '</div></div>';
            $('#span_video_review').prepend(s).fadeTo('slow', 1);
        }
        textarea.attr('value', '').focus();
    },
    doingReply: function() {
        var timer_doing = null;
        $('#Doing input[@type=submit]').click(function() {
            var content = $.trim($('#Doing textarea').val());
            if (content == null) {
                alert('记事内容不可为空！');
                $('#Doing textarea').focus();
                return;
            }
            if (timer_doing != null) {
                var d = new Date();
                if ((Date.parse(d.toUTCString()) - 60000) < timer_doing) {
                    alert('留言间隔不得少于1分钟！');
                    $('#Doing textarea').focus();
                    return;
                }
            } else {
                var d = new Date();
                timer_doing = Date.parse(d.toUTCString());
            }
            var ct = Pui.pos.elementTop($('#Doing')[0]);
            window.scrollTo(0, ct - 30);
            this.blur();
            setTimeout("Pui.space.doingReplyFill()", 1000);
            var content = escape(content.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace('\'', '‘'));
            Pui.loadScript(baseurl + "/space/mydoingajax.aspx?opreatetype=add&writecontent=" + content + "&userid=" + _space_user.uid, {
                random: false
            });
            return false;
        });
    },
    doingReplyFill: function() {
        var c = $.trim($('#Doing textarea').val());
        var s = '<li><div>' + c + '</div><p>书写于<span>现在</span><a href="javascript:;" onclick="$(this).parent().parent().hide()" class="is_login" title="删除">删</a></p></li>';
        if (!$('#Doing .nl')[0]) {
            $('#Doing h2').after('<div class="nl detail"></div>');
        }
        $(s).prependTo('#Doing .nl');
        $('#Doing textarea').attr('value', '').focus();
    },
    GetValidCodeImg: function() {
        ValidCodeURL = baseurl + "/video/ValidCode.aspx?type=1";
        document.getElementById('Comment') ? document.getElementById("validcode").src = ValidCodeURL + "&objid=" + flvid + "&ran=" + Math.random() : document.getElementById("validcode").src = ValidCodeURL + "&objid=" + _space_user.uid + "&ran=" + Math.random();
    },
    CodeImgLoader: function() {
        var s = '<a href="javascript:Pui.space.GetValidCodeImg();" title="看不清楚？请点击刷新验证码！" style="position:relative;top:6px;*top:4px;" ><img id="validcode" border=0  width="60" height="20" src="" /></a>';
        $('#tb_validcode').after(s).removeAttr('onfocus');
        $('#post_content').unbind('focus');
        $('#post_content').click(function() {
            if ($("#QuickComment").length > 0) {
                $(".f_v").hide();
                $("#QuickComment").hide();
            }
        });
		this.GetValidCodeImg();
    },
    SetValidCodeImg: function(what) {
        var ValidCodeHtml = '';
        ValidCodeHtml = '请输入验证码&nbsp;&nbsp;<input id="tb_validcode" type="text" onfocus="javascript:Pui.space.CodeImgLoader();" style="width:60px; border:1px #7B9EBD solid;margin:0 5px 0 0;" />';
        var s = $(what + ' .commentAdd .form .submit').html();
        $(what + ' .commentAdd .form .submit').html(ValidCodeHtml + s);
    },
    SendCallBack: function(v, sv) {
        if (v == 0) {
            alert("您的验证码错误！");
        }
        if (v == -1) {
            alert("您的验证码已失效。请点击验证码图片，重新获取验证码！");
        }
        setTimeout("$('#Comment .mDocument').eq(0).remove();", 1000);
        if ($('#Comment .cl').length > 1) {
            $('#Comment .cl').eq(0).remove();
            $('#Comment h3').eq(0).remove();
        }
        setTimeout("textarea.attr('value', '" + sv + "').focus();", 1000);
        setTimeout(function() {
            var icount = $('#CM h3 .title span').text() ? $('#CM h3 .title span').text() : 0;
            icount = parseInt(icount);
            var vtitle = $.trim($('title').html());
            var s_href = 'http://video.pomoho.com/review.aspx?flvid=' + flvid + '&icount=' + (icount - 1) + '&title=' + vtitle + '&uid=' + _space_user.uid;
            $('#Comment h3 .title span').text(icount - 1).parents('h3').find('.more a').attr('href', s_href);
        },
        1500);
    },
	/*背景墙播放页*/
	 emotions: function(what) {
        var emotionID = 1;
        $(what + ' .emotions').find('.l').click(function() {
            if (emotionID >= 2) {
                $('#emotion_Box').animate({
                    left: -(572 * (emotionID - 2))
                },
                1000);
                if (emotionID == 2) {
                    $(what + ' .l').removeClass('l_b').attr('title', '左边没有了');
                } else if (emotionID == 3) {
                    $(what + ' .r').addClass('r_b').attr('title', '向右翻');
                }
                emotionID--;
            }
            this.blur();
            return false;
        }).end().find('.r').click(function() {
            if (emotionID <= 2) {
                $('#emotion_Box').animate({
                    left: -(572 * emotionID)
                },
                1000);
                if (emotionID == 1) {
                    $(what + ' .l').addClass('l_b').attr('title', '向左翻');
                } else if (emotionID == 2) {
                    $(what + ' .r').removeClass('r_b').attr('title', '右边没有了');
                }
                emotionID++;
            }
            this.blur();
            return false;
        }).end().find('div a').each(function() {
            $(this).click(function() {
                var tmp = $(what + ' textarea').val() + $(this).find('img').attr('src').replace(/.+\/(em\d+)\.gif/g, '[$1]');
                $(what + ' textarea').val(tmp);
                return false;
            });
        });
    },
	emotionWRS: function(what) {
        var s = '';
        s += '<div style="position:relative;width:572px;height:60px;overflow:hidden;margin:5px auto;"><div id="emotion_Box" style="position:absolute;left:0;top:0;width:4800px;">';
        var l = 'http://static.pomoho.com/images/em/';
        var alt = ['黑星打', '大', '泡', '蹦', '继续', '狂', '黑星殴', '吹', '捅', '被殴', '飞', '嘘', '赖', '顶', '变', '滚球', '生', '膜拜', '转', '口', 'KI', '鬼', '抓狂', '扯', '流', '闭嘴', 'HI', '可爱', '摇', '躲', '多', '吉'];
        for (var i = 1; i <= 3; i++) {
            s += '<div style="width:572px;float:left;text-align:center;">';
            for (var j = (i - 1) * 11 + 1; j <= i * 11; j++) {
                if (j <= 32) {
                    s += '<a href="" title="' + alt[j - 1] + '" style="margin:0 1px;"><img src="' + l + 'em' + j + '.gif" height="50" width="50" /></a>';
                }
            }
            s += '</div>';
        }
        s += '</div></div>';
        s += '<a href="" class="l" title="左边没有了">向左翻</a><a href="" class="r r_b" title="向右翻">向右翻</a>';
        $(s).appendTo($('.emotions'));
        this.emotions(what);
       	this.commentLoad();
    },
	/*视频列表切换*/
	playlist: function(index) {
		var emotionID = index+1;
		var rowN=$('#VideoBox .row').length;
		$('#ListSwitch .playlist').find('.l').click(function() {
			if (emotionID >= 2) {
				$('#VideoBox').animate({left: -(900*(emotionID-2))}, 500);
				if (emotionID == 2) {
					$('#ListSwitch .l').removeClass('l_b').attr('title', '左边没有了');
				} else if (emotionID == rowN) {
					$('#ListSwitch .r').addClass('r_b').attr('title', '向右翻');
				}
				emotionID --;
			}
			this.blur();
			return false;
		}).end().find('.r').click(function() {
			if (emotionID <= (rowN-1)) {
				$('#VideoBox').animate({left: -(900*emotionID)}, 500);
				if (emotionID == 1) {
					$('#ListSwitch .l').addClass('l_b').attr('title', '向左翻');
				} else if (emotionID == (rowN-1)) {
					$('#ListSwitch .r').removeClass('r_b').attr('title', '右边没有了');
				}
				emotionID ++;
			}
			this.blur();
			return false;
		});
	},
	VideoWelter:function(){
		var videoBox=$('.playlist #VideoBox'),_self=this,rowN=$('.playlist #VideoBox .row').length;
		var video_id=flvid;
		var v_ww = 'current_'+video_id;
		videoBox.find('.row ul').each(function(i){
			var t=$(this);
			var v_vw = t.attr('id');
			if(v_vw==v_ww){
				t.addClass('ac');
				var index=videoBox.find('.row').index(t.parent()[0]);
				videoBox.animate({left: -(900*index)},500);
				if(index>0){$('.playlist .l').addClass('l_b').attr('title', '向左翻');}
				if(index==rowN-1){$('.playlist .r').removeClass('r_b').attr('title', '右边没有了');}
				_self.playlist(index);
			}
		});
	}
}
function SendCallBack(v, sv) {
    Pui.space.SendCallBack.call(this, v, sv);
}
Pui.video = {
    quote: function(bid) {
        Pui.space.commentQuote.call(this, bid);
    },
    collect: function() {
        Pui.space.video.collect.call(this);
    },
    relateVideo:function()
    {
        Pui.space.video.relateVideo();
    }
}
Pui.space.index = {
    init: function() {
        Pui.space.writeMenu();
        this.sortable();
    },
    sortable: function() {
        Pui.autoThumb('#Main .videolist img,#Main .piclist img,#Main .collList img', 120, 90);
        Pui.autoThumb('#Main .friend img,#Main .fans img', 90, 90);
        if (_is_login = true && typeof(_user.uid) != 'undefined' && _user.uid == _space_user.uid) {
            $('|<a href="http://www.pomoho.com/my/changemodule.aspx" target="_blank" class="skin_change">更换模版</a>|<a class="toggle_layout" href="" title="切换空间布局">切换布局</a>-<a class="save_sort" href="">保存设置</a><a href="http://static.pomoho.com/doc/spacehelp.shtml" target="_blank">帮助</a>').appendTo('#Menu p');
            $('#Bar').add('#Main').sortable({
                items: '.block',
                handle: 'h3',
                cursor: 'move'
            }).disableSelection();
            var Bar = $('#Bar'),
            Main = $('#Main');
            $('<div class="toggle_ui"><h6>切换布局</h6><ul><li class="l1"><span></span></li><li class="l2"><span></span></li></ul></div>').appendTo($('#Menu .toggle_layout'));
            $('#Menu .toggle_layout').hover(function() {
                $('.toggle_ui').css('display', 'block');
            },
            function() {
                $('.toggle_ui').css('display', 'none');
            });
            var tl1 = $('#Menu .toggle_ui .l1'),
            tl2 = $('#Menu .toggle_ui .l2');
            if ($('#Columns>div:first-child').attr('id') == 'Bar') {
                tl1.css('background-position', '-48px -218px');
                $('#Menu .toggle_layout').toggle(function() {
                    Bar.before(Main);
                    Bar.css('float', 'right');
                    Main.css('float', 'left');
                    tl1.css('background-position', '0 -218px');
                    tl2.css('background-position', '-48px -250px');
                },
                function() {
                    Bar.after(Main);
                    Bar.css('float', 'left');
                    Main.css('float', 'right');
                    tl2.css('background-position', '0 -250px');
                    tl1.css('background-position', '-48px -218px');
                });
            } else {
                tl2.css('background-position', '-48px -250px');
                $('#Menu .toggle_layout').toggle(function() {
                    Main.before(Bar);
                    Main.css('float', 'right');
                    Bar.css('float', 'left');
                    tl2.css('background-position', '0 -250px');
                    tl1.css('background-position', '-48px -218px');
                },
                function() {
                    Main.after(Bar);
                    Main.css('float', 'left');
                    Bar.css('float', 'right');
                    tl1.css('background-position', '0 -218px');
                    tl2.css('background-position', '-48px -250px');
                });
            }
            $('.block h3').hover(function() {
                $(this).css('cursor', 'move')
            },
            function() {
                $(this).css('cursor', 'default')
            });
			this.saveSort();
            this.editBlock('videoList');
            this.editBlock('picList');
            this.editBlock('collList');
            this.editBlock('blogList');
        }
        var bl = $('.bloglist ul li');
        bl.length > 10 ? bl.parent().css('height', '208px') : bl.parent().css('height', 'auto');
    },
    saveSort: function() {
        var L = $('#Columns>div:first-child').attr('id');
        var R = $('#Columns>div:last-child').attr('id');
        var L_block = $('#' + L).sortable('toArray').toString();
        var R_block = $('#' + R).sortable('toArray').toString();
        var oldSort = L + ',' + L_block + ';' + R + ',' + R_block;
        $('#Menu .save_sort').click(function() {
            var L = $('#Columns>div:first-child').attr('id');
            var R = $('#Columns>div:last-child').attr('id');
            var L_block = $('#' + L).sortable('toArray').toString();
            var R_block = $('#' + R).sortable('toArray').toString();
            var newSort = L + ',' + L_block + ';' + R + ',' + R_block;
            if (newSort == oldSort) {
                alert('您没有对模块作任何更改!');
            } else {
                $.ajax({
                    type: 'POST',
                    url: 'http://home.pomoho.com/do/space/indexmoduleorder.aspx',
                    data: 'objid=' + newSort + '&objtype=5&userid=' + _space_user.uid,
                    success: function(msg) {
                        alert('设置成功！');
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert(textStatus);
                    }
                });
            }
            return false;
        });
        var _self = this;
        $('#Menu .skin_change').click(function() {
            if ($('.skin_choose_ui').css('display') == 'none') {
                $('.skin_choose_ui').css('display', 'block');
            } else if ($('.skin_choose_ui')[0]) {
                return false;
            } else {
                _self.skin_choose();
            }
            return false;
        });
    },
    editBlock: function(block) {
        var _self = this;
        $('#' + block + ' h3').append('<span class="edit"><a href="">编辑</a></span>').find('.edit').click(function() {
            _self.editOrder(block + '_block');
            _self.autoThumb('.edit_pannel ul li img', 80, 60);
            return false;
        });
    },
    editOrder: function(a) {
        var doc = document;
        var docElement = doc.documentElement;
        var sHeight = docElement.clientHeight;
        var dH = docElement.scrollHeight > sHeight ? docElement.scrollHeight: sHeight;
        var sH = docElement.scrollTop;
        var s = '';
        s += '<div id="zhezhao" style="height:' + dH + 'px"></div>';
        if (a == 'blogList_block') {
            s += index.GetBlogByModule(_space_user.uid, a, sH, sHeight).value;
            s += '<div class="blog_all" id="videolist">';
            s += index.GetBlogAllList(_space_user.uid, 1).value;
            s += '</div>';
        } else if (a == 'videoList_block') {
            s += index.GetVideoByModule(_space_user.uid, a, sH, sHeight).value;
            s += '<div class="vl_all" id="videolist">';
            s += index.GetVideoAllList(_space_user.uid, 1).value;
            s += '</div>';
        } else if (a == 'collList_block') {
            s += index.GetFavoritByModule(_space_user.uid, a, sH, sHeight).value;
            s += '<div class="vl_all" id="videolist">';
            s += index.GetFavoritAllList(_space_user.uid, 1).value;
            s += '</div>';
        } else if (a == 'picList_block') {
            s += index.GetImgByModule(_space_user.uid, a, sH, sHeight).value;
            s += '<div class="vl_all" id="videolist">';
            s += index.GetImgAllList(_space_user.uid, 1).value;
            s += '</div>';
        }
        var block_you = $('#' + a);
        var zz = $('#zhezhao');
        if (block_you.css('display') == 'none') {
            zz.add(block_you[0]).css('display', 'block');
        } else if (block_you[0]) {
            return false;
        } else {
            $(s).prependTo('body').show();
            this.favo_click('#' + a + ' .favo .opera .checked', a);
            this.favo_click('#' + a + ' .favo li p a', a);
            this.favo_click('#' + a + ' .favo li>a', a);
            this.list_click('#' + a + ' .vl_all ul li:not(:last)', a);
            this.list_click('#' + a + ' .vl_all ul li:last', a);
            this.list_click('#' + a + ' .blog_all ul li:not(:last)', a);
            this.list_click('#' + a + ' .blog_all ul li:last', a);
            this.update_favo(a);
        }
        this.editOrder_close();
    },
    editOrder_close: function() {
        $('.vl_all').add('.blog_all').append('<a href="" class="close" title="关闭">关闭</a>');
        $('.edit_pannel .close').click(function() {
            $(this).parents('.edit_pannel').hide();
            $('#zhezhao').hide();
            return false;
        });
    },
    favo_click: function(c, blockID) {
        $(c).bind('click',
        function() {
            var t = $(this);
            var b = '#' + blockID;
            $(b + ' .favo li a').removeClass('ac');
            if (c == b + ' .favo .opera .checked' || c == b + ' .favo li p a') {
                t.parents().siblings('a').addClass('ac');
                t.parents().siblings('p').find('a').addClass('ac');
            } else if (c == b + ' .favo li>a') {
                t.addClass('ac');
                t.siblings('p').find('a').addClass('ac');
            } else {
                alert('选择器发生错误！');
            }
            return false;
        });
        $('.favo .opera .dele').each(function(i) {
            var t = $(this);
            t.click(function() {
                blockID == 'blogList_block' ? t.parent().siblings('a').text('此推荐位置为空...').css({
                    'color': '#999',
                    'text-decoration': 'line-through'
                }) : t.parent().siblings('a').find('img').attr('src', 'http://static.pomoho.com/themes/space/images/noimg.jpg').end().end().siblings('p').remove();
                var block_blank = blockID.replace('List_block', '') + (i + 1);
                t.parents('li').attr('id', 't0_' + block_blank);
                return false;
            });
        });
    },
    list_click: function(d, blockID) {
        var block_name = '';
        this.block_type = '';
        var b = '#' + blockID;
        switch (blockID) {
        case 'blogList_block':
            block_name = '博文';
            this.block_type = 4;
            break;
        case 'videoList_block':
            block_name = '视频';
            this.block_type = 1;
            break;
        case 'picList_block':
            block_name = '图片';
            this.block_type = 2;
            break;
        case 'collList_block':
            block_name = '收藏';
            this.block_type = 3;
            break;
        default:
            block_name = '内容';
        }
        var _self = this;
        $(d).bind('click',
        function() {
            var t = $(this);
            if ($('.favo li a').hasClass('ac')) {
                var favo_ac = $('.favo li>a.ac:first').parent();
                for (var i = 0,
                L = $('.favo li').length; i < L; i++) {
                    if (t.attr('id').slice(1) == $('.favo li')[i].getAttribute('id').slice(1)) {
                        alert('您已推荐过此' + block_name + '！');
                        return false;
                    }
                }
                var new_vl_ac = t.clone().animate({
                    opacity: 'show'
                },
                2000).insertBefore(favo_ac).append('<span class="opera"><a class="checked" href="">编辑</a><a class="dele" href="">删除</a></span>');
                new_vl_ac.find('a').addClass('ac');
                favo_ac.remove();
                new_vl_ac.unbind('click');
                _self.favo_click(b + ' .favo .opera .checked', blockID);
                _self.favo_click(b + ' .favo li p a', blockID);
                _self.favo_click(b + ' .favo li>a', blockID);
            } else {
                alert('请先选择要替换掉的推荐' + block_name + '！');
            }
            return false;
        });
    },
    update_favo: function(blockID) {
        var _self = this;
        $('#' + blockID + ' .favo .save').click(function() {
            f = function(i) {
                var a = $.trim($('#' + blockID + ' .favo ul li')[i].getAttribute('id')).slice(1);
                if (a.match('_') || !/^[\d]+$/.test(a) || /![0-9a-zA-Z]/.test(a)) {
                    a = 0;
                }
                return a;
            }
            var favo_order = '1,' + f(0) + ';2,' + f(1) + ';3,' + f(2) + ';4,' + f(3) + ';5,' + f(4) + ';6,' + f(5) + ';7,' + f(6) + ';8,' + f(7);
            $.ajax({
                type: 'POST',
                url: 'http://home.pomoho.com/do/space/indexmoduleorder.aspx',
                data: 'objid=' + favo_order + '&objtype=' + _self.block_type + '&userid=' + _space_user.uid,
                success: function(msg) {
                    alert('设置成功！');
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(textStatus);
                }
            });
            return false;
        });
    },
    skin_choose: function() {
        var s = '';
        s += '<div class=\"skin_choose_ui\"><div id=\"skinChoose\" class=\"skin_choose\">';
        s += index.GetUserStyle(_space_user.uid).value;
        s += '<div id="span_modulelist">';
        s += index.getStyleList(_space_user.uid, 1).value;
        s += '</div></div></div>';
		$(s).prependTo('body');
        this.skin_choose_click();
    },
    skin_choose_click: function() {
        this.mid = '';
        this.sid = '';
        var _self = this;
        var sk = $('.skin_list');
        var sk_now = $('.skin_now');
        sk.find('p button').hover(function() {
            $(this).addClass('hover');
        },
        function() {
            $(this).removeClass('hover');
        });
        sk.find('li').click(function() {
            sk.find('li .info').css('display', 'none');
            var t = $(this);
            var m_s = $.trim(t.attr('id')).split('_');
            _self.mid = m_s[0].replace('m', '');
            _self.sid = m_s[1].replace('s', '');
            if (!/^[\d]+$/.test(_self.mid) || !/^[\d]+$/.test(_self.sid)) {
                alert('模板ID异常！');
            } else {
                _self.skin_preview(_self.mid);
                t.find('.info').css('display', 'block');
                sk.find('.skin_save').addClass('hover');
            }
            return false;
        });
        var skin_now_id = $.trim(sk_now.find('a').attr('id')).replace('m', '').replace('_', '');
        sk.find('.skin_close').click(function() {
            if (typeof(_self.mid) != 'undefined' && _self.mid != '' && _self.mid != skin_now_id) {
                var cc = confirm('您修改了模板主题，关闭将不会保存。确定关闭？');
                if (cc) {
                    $('.skin_choose_ui').slideUp('fast');
                } else {
                    return;
                }
            } else {
                $('.skin_choose_ui').slideUp('fast');
            }
        });
        sk_now.find('a').click(function() {
            return false;
        });
        sk.find('.skin_save').click(function() {
            var skin_id = _self.sid;
            if (typeof(_self.mid) != 'undefined' && (_self.mid == '' || _self.mid == skin_now_id)) {
                alert('您没有对模板进行修改，无需保存！');
            } else if (!/^[\d]+$/.test(skin_id) || !/^[\d]+$/.test(_self.mid)) {
                alert('模板ID获取异常！');
            } else {
                $.ajax({
                    type: 'POST',
                    url: 'http://home.pomoho.com/do/space/changestyle.aspx',
                    data: 'userid=' + _space_user.uid + '&styleid=' + skin_id,
                    success: function(msg) {
                        alert('模板设置成功！');
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        alert(textStatus);
                    }
                });
                $('.skin_choose_ui').slideUp('fast');
            }
        });
    },
    skin_preview: function(moduleID) {
        $('link[href^="http://adface.pomoho.com"]').remove();
        var css_link = 'http://adface.pomoho.com/getuserstyle.aspx?userid=' + _space_user.uid + '&moduleid=' + moduleID;
        var d = null;
        d = document.createElement('link');
        d.setAttribute('type', 'text/css');
        d.setAttribute('rel', 'stylesheet');
        d.setAttribute('href', css_link);
        var dHead = document.getElementsByTagName("head");
        if (dHead != null) {
            dHead[0].appendChild(d);
        }
    }
}
Pui.space.video = {
    init: function() {
        Pui.space.init();
        Pui.loadScript('http://live.pomoho.com/getxmldata.aspx?type=2&ids=' + flvid + '_999');
		Pui.space.emotionWRS('#Comment');
        Pui.space.commentReply('#Comment');
        Pui.space.hideComment(5);
        Pui.autoThumb('.albumlist li img', 78, 58);
		this.addVideo(hotVideoJson,'hotvideo','推荐视频','','#Comment',2,6,"P3S04",false);
		this.addVideo(hotVideoTopJson,'popvideo','昨日排行','','#Bar',0,3,"P3P39",true);
		if(document.getElementById('SpaceColumn')){
			this.gotoLink();
		}
		//Pui.space.video.relateVideo();
		Pui.space.video.userRelateVideo();
    },
    share: function(link, title, content) {
        var itieba_share = 'http://tieba.baidu.com/i/sys/share?link=' + link + '&type=video&title=' + title + '&content=' + content;
        if (!window.open(itieba_share, 'itieba', 'toolbar=0,resizable=1,scrollbars=yes,status=1,width=626,height=436')) {
            location.href = itieba_share;
        }
    },
    collect: function() {
        Pui.loadScript("http://www.pomoho.com/do/video/dealajaxdata.aspx?itype=2&imdbid=" + flvid);
    },
    gotoLink: function() {
        var vTitle = encodeURIComponent($('title').html().replace(/(^\s*)|(\s*$)/g, ""));
        var vLink = encodeURIComponent('http://home.pomoho.com/' + _space_user.username + '/' + flvid);
        var vContent = encodeURIComponent('http://video.pomoho.com/swf/out_player.swf?flvid=' + flvid);
        var vContentTieba = encodeURIComponent('http://video.pomoho.com/swf/out_player.swf?flvid=' + flvid+'&qudao=tieba');
		var vBogo = encodeURIComponent('http://video.pomoho.com/swf/out_player.swf?flvid=' + flvid+'&outall=true&qudao=51com');
        var vSource = encodeURIComponent('爆米花网');
        var vSourceUrl = encodeURIComponent('http://www.pomoho.com/');
        var s = '<span class="icos"><a id="wuyicom" href="http://diary.51.com/mod/diary_video_interface.php?vaddr=' + vBogo+ '&title=' + vTitle + '&charset=utf-8" target="_blank" title="51交友社区">转贴至51交友社区</a><a id="QQ" href="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + vLink+ '&title=' + vTitle + '&charset=utf-8" target="_blank" title="QQ空间">转贴至QQ空间</a><a id="renren" href="http://share.renren.com/share/buttonshare.do?link=' + vLink + '&title=' + vTitle + '" target="_blank" title="转贴至人人网">转贴至人人网</a><a id="kaixin" href="http://www.kaixin001.com/repaste/share.php?rurl=' + vLink + '&rcontent=' + vLink + '&rtitle=' + vTitle + '" target="_blank" title="转贴至开心网">转贴至开心网</a><a id="sina" href="http://v.t.sina.com.cn/share/share.php?c=spr_web_bd_pomoho_weibo&url=' + vLink + '&title=' + vTitle + '&source=' + vSource + '&sourceUrl=' + vSourceUrl + '&appkey=1854178289&pic=' +pic+ '" target="_blank" title="转贴至新浪微博">转贴至新浪微博</a><a id="itieba" href="" onclick="Pui.space.video.share(\'' + vLink + '\',\'' + vTitle + '\',\'' + vContentTieba + '\');return false;" title="转贴至i贴吧">转贴至i贴吧</a><a id="feixin" href="http://space.fetion.com.cn/api/share?source='+vSource+'&url='+vLink+'&title='+vTitle+'" target="_blank" title="转发至飞信空间">转发至飞信空间</a></span>';
        $(s).appendTo('.video_info .handle');
        this.zz();
    },
    zz: function(mv) {
        var urlParm = "";
        var htmlcode = '';
        var vTitle = encodeURIComponent($('title').html().replace(/(^\s*)|(\s*$)/g, ""));
        var vLink ='http://home.pomoho.com/' + _space_user.username + '/' + flvid;
        var vContent = 'http://video.pomoho.com/swf/out_player.swf?flvid=' + flvid+"&outall=true";
        var vSource = encodeURIComponent('爆米花网');
        var vSourceUrl = encodeURIComponent('http://www.pomoho.com/');
        var s = '';
        s += '<div id="ZZ" style="display:none;">';
        s += ' <div class="s1">';
        urlParm = "flvid";
        htmlcode = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="480" height="396" id="object"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="movie" value="'+vContent+'" /><embed src="'+vContent+'" quality="high" width="480" height="396" allowScriptAccess="always"/></object>';
        if (String(window.location).match(/http:\/\/video\.dvod.*/)) {
            s += '  此节目地址（URL）<br /><input type="text" class="url" value="http://video.dvod.com.cn/news/' + flvid + '.shtml" /><br />';
        } else {
            s += '  此节目地址（URL）<br /><input type="text" class="url" value="'+vLink+'" /><br />';
        }
        s += '  把播放器显示到个人空间或Blog<br /><input type="text" class="url" value="'+vContent+'" /><br />';
        s += '  HTML代码,适用于个人空间（或其他类型的Blog）<br /><input type="text" class="url" value="" /><br />';
        s += '  BBS代码<br /><input type="text" class="url" value="[flash]'+vContent+'[/flash]" />';
        s += ' </div>';
        s += '  <p><a href="" onclick="$(\'#ZZ\').slideUp();return false;">关闭</a></p>';
        s += '</div>';
        var vPath = '#VideoPlayer #Handle';
        $(s).appendTo($('#Space')).css({
            'z-index': '9999',
            'top': '552px',
            'left': '16px'
        });
        $(vPath).find('.s4').click(function() {
            $('#ZZ').slideToggle('slow');
            this.blur();
            return false;
        });
        $('#ZZ .url').eq(2).attr('value', htmlcode).end().hover(function() {
            $(this).select();
        },
        function() {
            $(this).blur();
        });
    },
    hideComment: function(num) {
        if (String(window.location).match(/http:\/\/home.*/)) {
            $('#Comment .mDocument').filter(':gt(19)').hide();
        } else {
            $('#Comment .mDocument').filter(':gt(19)').hide();
        }
        $('#Comment h3 span.count').html(20);
    },
    relatedSearch: function() {
        var s_domain = document.referrer.toString();
       /* $('<div class="loading">关键词检索中...</div>').appendTo($('#VideoPlayer'));*/
        if (s_domain.indexOf('baidu.com') != -1 || s_domain.indexOf('google.com') != -1 || s_domain.indexOf('sogou.com') != -1 || s_domain.indexOf('soso.com') != -1 || s_domain.indexOf('search.pomoho.com') != -1) {
            Pui.ajaxLoad('GET', 'http://home.pomoho.com/do/interfaces/relatedwords.aspx', 'videoid=' + flvid + '&fromurl=' + document.referrer.toString().replace('?', '&'), '', '.loading',
            function() {
                if (parseInt(_getDATA) != -1) {
                    $(_getDATA).appendTo($('#VideoPlayer'));
                    getrootKey();
                }
            });
        } else {
            Pui.ajaxLoad('GET', 'http://home.pomoho.com/do/interfaces/relatedwords.aspx', 'videoid=' + flvid + '&fromurl=', '', '.loading',
            function() {
                if (parseInt(_getDATA) != -1) {
                    $(_getDATA).appendTo($('#VideoPlayer'));
                    getrootKey();
                }
            });
        }
        function keywordsAlign() {
            var ul = $('.related_search ul');
            var ulno = ul.length;
            var lino = ul.eq(0).find('li').length;
            var key_arr = new Array();
            for (var j = 0; j < lino; j++) {
                for (var i = 0; i < ulno; i++) {
                    ul.eq(i).find('li').eq(j).find('a').text(ul.eq(i).find('li').eq(j).find('a').text().toString().strLen(10));
                    var li_width = ul.eq(i).find('li').eq(j).width();
                    key_arr.push(li_width);
                }
                function sortNum(a, b) {
                    return b - a;
                }
                var a = key_arr.slice(j * ulno).sort(sortNum);
                for (var i = 0; i < ulno; i++) {
                    ul.eq(i).find('li').eq(j).css('width', a[0]);
                }
            }
        }
        function getrootKey() {
            var rootKey = _keywords.root_key;
			alert(rootKey);
            $('#SearchForm #SearchInput').val(rootKey).css('color', '#999').focus(function() {
                var t = $(this);
                if (t.val() == rootKey) {
                    t.val('').css('color', '#000')
                }
            }).blur(function() {
                var t = $(this);
                if ($.trim(t.val()) == '') {
                    t.val(rootKey).css('color', '#999');
                }
            });
        }
    },
	addVideo:function(json,id,title,more,con,m,r,s,g)
	{
	    if(typeof(json)!="object")
        {
            return;
        }
        var videoList=function()
        {
		    if(json==null||json.length==0)
		    {
		        return;
		    }
			var n=json.length,div=document.createElement('div');
			var ul='',href='';
			if(more==null||more=='')
			{
			    more="http://www.pomoho.com/"+json[0].channelText+"/"+json[0].channelText+",video,24hour,1";
			}
			for(var i=0;i<n;i++){
			    if(g)
			    {
			        href=json[i].spaceURL+"/"+json[i].videoID+"?"+s;
			    }
			    else
			    {
			        href="http://search.pomoho.com/videosearch.aspx?_keyword="+encodeURIComponent(json[i].videoName)+"&_f="+s+"&vid="+json[i].videoID;
			    }
				ul='<ul><li class="link_mask"><a target="_blank" title="'+json[i].videoName+'" href="'+href+'"></a></li><li class="vimg"><a target="_blank" href="'+href+'"><img src="'+json[i].imgURL+'" alt="'+json[i].videoName+'" /></a></li><li class="vtitle"><a target="_blank" title="'+json[i].videoName+'" href="'+href+'">'+json[i].videoName+'</a></li></ul>';
				if(i%r==0){
					var row=document.createElement('div');				
				}
				$(row).attr('class','row').append($(ul)).appendTo($(div).attr('class','showblock'));
			}
			var block=$('<div class="block '+id+'" id="'+id+'">').append('<h3><span class="title">'+title+'</span><span class="more"><a href="'+more+'">更多</a></span></h3>').append($(div));
			switch (m){
				case 0:block.appendTo($(con));break;
				case 1:block.prependTo($(con));break;
				case 2:block.insertBefore($(con));break;
				case 3:block.insertAfter($(con));break;
			}
		};
		setTimeout(function(){videoList(json)},2000);
	},
	relateVideo:function()
	{
        if(typeof(relateVideoJson)=="object")
        {
            setTimeout(function()
                        {
                            var str=Pui.space.video.showVideoList(relateVideoJson,decodeURIComponent(videoTitle),"相关视频","P3P32",9)
                            if(str!="")
                            {
                                $("#relateVideo").append(str);
                            }
                        },200);
        }
        window.playNext=function(){return false;};
	},
	showVideoList:function(list,title,titleName,code,num)
    {
        if(typeof(list)=="object" && !(list instanceof Array))
        {
            if(list.videoList instanceof Array)
            {
                list=list.videoList;
            }
            else
            {
                list=[];
            }
        }
        if(list.length==0) return "";
        var tmpStatSource=code;
        num=num||9;
        var fristKeywordstitle=title||list[0].videoName;
        var fristKeywordsEncodeTitle=encodeURIComponent(fristKeywordstitle);
        var str="<div class=\"block videolist\">";
        str+="<h3><span class=\"title\">"+titleName+"</span>";
        str+="<span class=\"more\"><a target=\"_blank\" href=\"http://search.pomoho.com/videosearch.aspx?_keyword="+fristKeywordsEncodeTitle+"&_f=P3SO3\" id=\"aHrefVideo\" target=\"_blank\">更多</a></span></h3>";
        var temp=","+fristKeywordstitle+",";
	    str+="<div class=\"showblock\">";
	    str+="<ul>";
        for (var i = 0; i < list.length && 0 < num; i ++)
        {
            if(temp.indexOf(","+list[i].videoName+",")>-1)
            {
                continue;
            }
            num--;
            temp+=list[i].videoName+",";
	        str+="<li>";
	        str+="<a href=\"http://home.pomoho.com/"+list[i].spaceURL+"/"+list[i].videoID+"?"+tmpStatSource+"\" target=\"_blank\" title=\""+list[i].videoName+"\"><img src=\""+list[i].imgURL+"\" alt=\""+list[i].videoName+"\"/></a>";
	        str+="<p><a href=\"http://home.pomoho.com/"+list[i].spaceURL+"/"+list[i].videoID+"?"+tmpStatSource+"\" target=\"_blank\" title=\""+list[i].videoName+"\">"+list[i].videoName+"</a></p>";
	        str+="</li>";
        }
        str+="</ul>";
        str+="</div>";
        str+="</div>";
        if(temp!=(','+fristKeywordstitle+','))
        {
           return str;
        }
        return "";
    },
    userRelateKeyWords:function(list,title,titleName,code,num)
    {
        if(list.length==0) return "";
        var tmpStatSource=code;
        num=num||9;
        var color=['color:#666666;','color:#0000ff;'];
        var fristKeywordstitle=title||list[0].keyWord;
        var fristKeywordsEncodeTitle=encodeURIComponent(fristKeywordstitle);
        var str="<div class=\"block videolist\">";
        str+="<h3><span class=\"title\">"+titleName+"</span>";
        str+="<span class=\"more\"><a target=\"_blank\" href=\"http://search.pomoho.com/videosearch.aspx?_keyword="+fristKeywordsEncodeTitle+"&_f=P3SO3\" id=\"aHrefVideo\" target=\"_blank\">更多</a></span></h3>";
        str+="<div class=\"showblock antistop\">";
        str+="<p>";
        for(var i=0;i<list.length&& 0<num; i++)
        {
    	    str+="<a href=\"http://search.pomoho.com/videosearch.aspx?_keyword="+encodeURIComponent(list[i].keyWord)+"&_f="+tmpStatSource+"\" title=\""+list[i].keyWord+"\" target=\"_blank\" style=\""+color[Math.floor(Math.random()*color.length)]+"\">"+list[i].keyWord+"</a>";
    	}
        str+="</p>";
        str+="</div>";
        str+="</div>";
        return str;
    },
    userRelateVideo:function()
    {
        var testReferrer=function()
	    {
	        var cookieName="userPlayListTag";
	        //var strUrl='http://video.baidu.com/s?n=1&word=%25b7%25c7%25b3%25cf%25ce%25f0%25c8%25c5%25&f=4';
	        var strUrl=document.referrer;
	        var strKeyWord=getRequest(strUrl,'word');
	        if(strKeyWord=='')
	        { 
	            var strKeyWords=cookie(cookieName);
	            if(strKeyWords==null||strKeyWords=='') return '';
	            var arrObj=eval('('+strKeyWords+')');
	            if(typeof(arrObj)!='object') return '';
	            var str=Pui.space.video.userRelateKeyWords(arrObj,null,"你可能还会喜欢","p3S05",10);
                if(str!="")
                {
			        $($("#userRelateVideo")[0]).append(str);
                }
	        }
	        else
	        {
                $.getJSON("http://relative.pomoho.com/getrelatvevideojson.aspx?jsoncallback=?", {count: 9, videoid:flvid,title:strKeyWord,'encode':'gb2312'}, function(json)
                {
                    Pui.LazyLoad.testAlert('json.length='+json.length);
                    if(json!=null&&json.videoList.length>0)
                    {
                        setCookie(cookieName,json.videoTitle);
	                    var str=Pui.space.video.showVideoList(json.videoList,null,"你可能还会喜欢","p3p05",6);
	                    if(str!="")
	                    {
					        $($("#userRelateVideo")[0]).append(str);
	                    }
                    }
                 });
             }
	    }
	    function getRequest(url,key)
        {
            if(url==null||url==''||url.lastIndexOf("?")==-1) return '';
            if(key==null||key=='') return '';
            var start=url.lastIndexOf("?");
            var strUrl=url.substr(start);
            var strkey=key.lastIndexOf('=')==key.length-1?key:key +'=';
            start=strUrl.indexOf(strkey);
	        if(start>-1)
	        {
	            start+=strkey.length;
		        var end=strUrl.indexOf('&',start);
		        strUrl=strUrl.substr(start);
		        if(end>start)
		        {
			        strUrl=strUrl.substr(0,end-start);
		        }
		        return strUrl;
	        }
            return '';
        }
	    var cookie=function (name,value,options)
	    {
		    if(typeof(value)!='undefined'){
			    options=options||{
			    };
			    if(value===null){
				    value='';
				    options.expires=-1;
			    }var expires='';
			    if(options.expires&&(typeof(options.expires)=='number'||options.expires.toUTCString)){
				    var date;
				    if(typeof(options.expires)=='number'){
					    date=new Date();
					    date.setTime(date.getTime()+(options.expires*24*60*60*1000));
    					
				    }else {
					    date=options.expires;
    					
				    }expires='; expires='+date.toUTCString();
    				
			    }var path=options.path?'; path='+options.path:'; path=/';
			    var domain=options.domain?'; domain='+options.domain:'';
			    var secure=options.secure?'; secure':'';
			    document.cookie=[name,'=',escape(value),expires,path,domain,secure].join('');
    			
		    }else {
			    var cookieValue=null;
			    if(document.cookie&&document.cookie!=''){
				    var cookies=document.cookie.split(';');
				    for(var i=0;i<cookies.length;i++){
					    var cookie=jQuery.trim(cookies[i]);
					    if(cookie.substring(0,name.length+1)==(name+'=')){
						    cookieValue=unescape(cookie.substring(name.length+1));
						    break;
					    }
				    }
			    }return cookieValue;
		    }
	    }
	    var setCookie=function(cookiename,cookievalue)
	    {
	        var strKeyWords=cookie(cookiename);
	        var strObj="{\"keyWord\":\""+cookievalue+"\"}";
	        var str=strObj;
	        if(strKeyWords!=null&&strKeyWords!="")
	        {    
                var arrobj=eval('('+strKeyWords+')');
                if(arrobj instanceof Array)
                {
                    for(var i=0;i<arrobj.length&&i<10;i++)
                    {
                        if(arrobj[i].keyWord==cookievalue)
                        {
                            continue;
                        }
                        str += ",{\"keyWord\":\""+arrobj[i].keyWord+"\"}";
                    }
                }
	        }
	        strKeyWords="["+str+"]";
	        cookie(cookiename,strKeyWords,{expires:365,domain:"pomoho.com"});
	    }
	    if($("#userRelateVideo").length==0)
	    {
	        $("<div>").attr({"id":"userRelateVideo"}).prependTo($("#Bar"));
	    }
        Pui.LazyLoad._initialize($("#userRelateVideo")[0]);
        Pui.LazyLoad.load(testReferrer);
    }
}
Pui.space.blog = {
    init: function() {
        Pui.space.writeMenu();
        Pui.autoThumb('.albumlist li img', 78, 58);
    }
}
Pui.space.album = {
    setting: {
        href: window.location.toString(),
        thumb_opacity: 0.5,
        loader_image: '',
        start_label: '开始自动播放',
        stop_label: '停止自动播放',
        play_span: 5000,
        thumb_num: 5
    },
    init: function() {
        Pui.space.writeMenu();
        this.activeImg();
        this.setupElements();
        this.activePos();
        this.checkCookie();
    },
    activeImg: function() {
        var context = this;
        if ($.browser.version == 6.0) {
            $('.ad-thumbs li a img').css('margin-top', ($('.ad-thumbs li a').height() - $('.ad-thumbs li a img').height()) * 0.5)
        }
        if (this.setting.thumb_opacity < 1) {
            $('.ad-thumbs li').find('img').css('opacity', this.setting.thumb_opacity);
        };
        $('.ad-thumbs li a').each(function(i) {
            $(this).attr('href', $(this).attr('href') + '#Main').hover(function() {
                if (!$(this).is('.ad-active') && context.setting.thumb_opacity < 1) {
                    $(this).find('img').fadeTo(300, 1)
                }
            },
            function() {
                if (!$(this).is('.ad-active') && context.setting.thumb_opacity < 1) {
                    $(this).find('img').fadeTo(300, context.setting.thumb_opacity)
                }
            }).addClass('ad-thumb' + i);
            if (typeof(context.setting.href) != 'undefined' && (context.setting.href == $(this).attr('href') || context.setting.href == $(this).attr('href').split('#')[0])) {
                $(this).addClass('ad-active').find('img').css('opacity', 1);
                var index = [i];
                context.showImg(index);
            }
        });
    },
    setupElements: function() {
        this.initBackAndForward();
        var $controls = $('.ad-controls');
        var $gallery_info = $('<p class="ad-info">' + ($('.ad-thumbs li a').index($('.ad-active')[0]) + 1) + ' / ' + $('.ad-thumbs li a').length + '</p>');
        $controls.append($gallery_info).append($('<p class="notes">快捷键：上一张：← 下一张：→</p>'));
        var $start_link = $('<span class="ad-slideshow-start" title="' + this.setting.start_label + '">' + this.setting.start_label + '</span>');
        var $stop_link = $('<span class="ad-slideshow-stop" title="' + this.setting.stop_label + '">' + this.setting.stop_label + '</span>');
        var $countdown = $('<span class="ad-slideshow-countdown"></span>');
        var $control = $('<div class="ad-slideshow-controls"></div>');
        $controls.append($control.append($start_link).append($stop_link).append($countdown));
        $start_link.hide();
        $countdown.hide();
        var autoRun = this.getCookie('autoRun');
        if (!autoRun) {
            $stop_link.show();
            $start_link.hide();
        } else {
            $stop_link.hide();
            $start_link.show();
        }
        var context = this;
        $start_link.click(function() {
            $stop_link.show().css('display', 'inline-block');
            $start_link.hide();
            $controls.addClass('ad-slideshow-running');
            context.next();
            context.delCookie('autoRun', 0);
        });
        $stop_link.click(function() {
            $countdown.hide();
            $stop_link.hide();
            $start_link.show();
            $controls.removeClass('ad-slideshow-running');
            context.setCookie('autoRun', 0, 24 * 60 * 60 * 1000);
            window.clearInterval(false);
        });
    },
    next: function() {
        var context = this;
        clearInterval(false);
        var interval = window.setInterval(function() {
            var now_active = $('.ad-thumbs li a').index($('.ad-active')[0]);
			var next_active = now_active + 1;
            if (next_active == $('.ad-thumbs li').length) {
                window.location = $('.ad-thumbs li a')[0].href;
            } else {
                window.location = $('.ad-thumbs li a')[next_active].href;
            }
        },
        this.setting.play_span);
    },
    showImg: function(index) {
        var context = this;
        var img_container = $(document.createElement('div')).addClass('ad-image');
        img_container.append('<span id="loader" style="background:red;padding:4px 10px;color:white;">图片加载中 稍候...</span>');
        var $image = $('.ad-thumbs li a:eq(' + index + ')');
        var img = $(new Image()).attr('src', $image.attr('pic'));
        if (img[0].readyState != 'complete') {
            setTimeout(function() {
                img_container.append(img);
                var size = context.getContainedImageSize(img.width(), img.height());
                img.attr('width', size.width);
                img.attr('height', size.height);
                img_container.css({
                    width: size.width + 'px',
                    height: size.height + 'px'
                });
                context.centerImage(img_container, size.width, size.height);
                $('#loader').hide();
            },
            500);
        } else if (img[0].readyState == 'complete') {
            setTimeout(function() {
                img_container.append(img);
                var size = context.getContainedImageSize(img.width(), img.height());
                img.attr('width', size.width);
                img.attr('height', size.height);
                img_container.css({
                    width: size.width + 'px',
                    height: size.height + 'px'
                });
                context.centerImage(img_container, size.width, size.height);
                $('#loader').hide();
            },
            500);
        }
        $('.ad-image-wrapper').prepend(img_container);
        var desc = this.getDescription($image, img_container);
        if (desc) {
            $('.ad-image-wrapper').append(desc);
            var width = $('.ad-image-wrapper').width() - parseInt(desc.css('padding-left'), 10) - parseInt(desc.css('padding-right'), 10);
            desc.css('width', width + 'px');
        };
        this.initNextAndPrev();
    },
    getContainedImageSize: function(image_width, image_height) {
        var image_wrapper = $('.ad-image-wrapper');
        if (image_height > image_wrapper.height()) {
            var ratio = image_width / image_height;
            image_height = image_wrapper.height();
            image_width = image_wrapper.height() * ratio;
        };
        if (image_width > image_wrapper.width()) {
            var ratio = image_height / image_width;
            image_width = image_wrapper.width();
            image_height = image_wrapper.width() * ratio;
        };
        return {
            width: image_width,
            height: image_height
        };
    },
    centerImage: function(img_container, image_width, image_height) {
        img_container.css('top', '0px');
        var image_wrapper = $('.ad-image-wrapper');
        if (image_height < image_wrapper.height()) {
            var dif = image_wrapper.height() - image_height;
            img_container.css('top', (dif / 2) + 'px');
        };
        img_container.css('left', '0px');
        if (image_width < image_wrapper.width()) {
            var dif = image_wrapper.width() - image_width;
            img_container.css('left', (dif / 2) + 'px');
        };
    },
    getDescription: function(image) {
        var desc = false;
        if (image.find('img').attr('alt').length) {
            var title = '';
            if (image.find('img').attr('alt').length) {
                title = '<strong class="ad-description-title">' + image.find('img').attr('alt') + '</strong>';
            };
            desc = $('<p class="ad-image-description">' + title + '</p>');
        };
        return desc;
    },
    activePos: function() {
        var now_active = $('.ad-thumbs li a').index($('.ad-active')[0]) + 1;
        var group = now_active / this.setting.thumb_num;
        var group_move = group > parseInt(group) ? parseInt(group) : parseInt(group) - 1;
        var width = $('.ad-nav').width() + 9;
        $('.ad-thumbs').scrollLeft(width * group_move);
    },
    initBackAndForward: function() {
        var context = this;
        var $scroll_forward = $('<div class="ad-forward" title="往右移动"></div>');
        var $scroll_back = $('<div class="ad-back" title="往左移动"></div>');
        $('.ad-nav').append($scroll_forward).prepend($scroll_back);
        var has_scrolled = 0;
        var thumbs_scroll_interval = false;
        $scroll_back.add($scroll_forward[0]).click(function() {
            var width = $('.ad-nav').width() + 9;
            if ($(this).is('.ad-forward')) {
                var left = $('.ad-thumbs').scrollLeft() + width;
            } else {
                var left = $('.ad-thumbs').scrollLeft() - width;
            };
            var thumb_group = Math.ceil($('.ad-thumbs li').length / context.setting.thumb_num);
            left <= 0 ? $scroll_back.attr('title', '左边没有了') : $scroll_back.attr('title', '往左移动');
			left >= thumb_group * width ? $scroll_forward.attr('title', '右边没有了') : $scroll_forward.attr('title', '往右移动');
			if (left >= thumb_group * width) {
                left = (thumb_group - 1) * width;
            }
            $('.ad-thumbs').animate({
                scrollLeft: left + 'px'
            });
            return false;
        }).css('opacity', 0.6).hover(function() {
            $(this).fadeTo(300, 1);
        },
        function() {
            $(this).fadeTo(300, 0.6)
        });
    },
    initKeyEvents: function() {
        var context = this;
        $(document).keydown(function(e) {
            if (e.keyCode == 39) {
                context.nextImage();
            } else if (e.keyCode == 37) {
                context.prevImage();
            };
        });
    },
    initNextAndPrev: function() {
        this.initKeyEvents();
        var $next_link = $('<div class="ad-next" title="下一张图片"><div class="ad-next-image"></div></div>');
        var $prev_link = $('<div class="ad-prev" title="上一张图片"><div class="ad-prev-image"></div></div>');
        $('.ad-image-wrapper').append($next_link).append($prev_link);
        var context = this;
        $prev_link.add($next_link).mouseover(function(e) {
            $(this).css('height', $('.ad-image-wrapper').height());
            $(this).find('div').show();
        }).mouseout(function(e) {
            $(this).find('div').hide();
        }).click(function() {
            if ($(this).is('.ad-next')) {
                context.nextImage();
            } else {
                context.prevImage();
            };
        }).find('div').css('opacity', 0.7);
    },
    nextImage: function(callback) {
        var now_active = $('.ad-thumbs li a').index($('.ad-active')[0]);
		var next_active = now_active + 1;
        if (next_active == $('.ad-thumbs li').length) {
            window.location = $('.ad-thumbs li a')[0].href
        } else {
            window.location = $('.ad-thumbs li a')[next_active].href;
        }
    },
    prevImage: function() {
        var now_active = $('.ad-thumbs li a').index($('.ad-active')[0]);
		var prev_active = now_active - 1;
        var last_thumb = $('.ad-thumbs li').length - 1;
        if (prev_active < 0) {
            window.location = $('.ad-thumbs li a')[last_thumb].href
        } else {
            window.location = $('.ad-thumbs li a')[prev_active].href;
        }
    },
    getCookie: function(c_name) {
        if (document.cookie.length > 0) {
            c_start = document.cookie.indexOf(c_name + "=");
			if (c_start != -1) {
                c_start = c_start + c_name.length + 1;
				c_end = document.cookie.indexOf(";", c_start);
				if (c_end == -1) c_end = document.cookie.length
                return unescape(document.cookie.substring(c_start, c_end))
            }
        }
        return "";
    },
    setCookie: function(c_name, value, expiredays) {
        var exdate = new Date();
		exdate.setDate(exdate.getDate() + expiredays);
		document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "": ";expires=" + exdate.toGMTString())
    },
    delCookie: function(c_name, value) {
        var exdate = new Date();
        exdate.setTime(exdate.getTime() - 10000);
        document.cookie = c_name + "=" + escape(value) + "; expires=" + exdate.toGMTString();
    },
    checkCookie: function() {
        var autoRun = this.getCookie('autoRun');
        var $start_link = $('<span class="ad-slideshow-start" title="' + this.setting.start_label + '">' + this.setting.start_label + '</span>');
        var $stop_link = $('<span class="ad-slideshow-stop" title="' + this.setting.stop_label + '">' + this.setting.stop_label + '</span>');
        if (!autoRun || autoRun == 1) {
            this.nextLoop();
        }
    },
    nextLoop: function() {
        window.setInterval(function() {
            var now_active = $('.ad-thumbs li a').index($('.ad-active')[0]);
			var next_active = now_active + 1;
            if (next_active == $('.ad-thumbs li').length) {
                window.location = $('.ad-thumbs li a')[0].href;
            } else {
                window.location = $('.ad-thumbs li a')[next_active].href;
            }
        },
        this.setting.play_span);
    }
}
Pui.space.doing = {
    init: function() {
        Pui.space.writeMenu();
        if (typeof(_servertime) == "undefined") {
            _servertime = 0;
            Pui.ui.loadServerTime();
        }
    },
    timeStamp: function() {
        return {
            f_gettime_bytick: function(itime) {
                var curDay = new Date();
                curDay.setTime((itime - 62135596800) * 1000);
                return (curDay.getFullYear() + "-" + parseInt(curDay.getMonth() + 1) + "-" + curDay.getDate() + " " + curDay.getHours() + ":" + curDay.getMinutes());
            },
            gettimespan: function(itime) {
                if (itime >= 24 * 3600) {
                    stime = f_gettime_bytick(_servertime - itime);
                } else {
                    if (itime > 3600) {
                        stime = Math.floor(itime / (3600)) + '小时前';
                    } else {
                        stime = Math.ceil(itime / 60) + '分钟前';
                    }
                }
                return stime;
            },
            timeStand: function(objID, timeClass, stitle) {
                if (objID != "UserInfo" && timeClass != "t_login") {
                    var name = '#' + objID + ' .' + timeClass;
                    __obj = $(name);
                    __stitle = stitle;
                    __time = parseInt(_servertime) - parseInt(__obj.html());
                    setTimeout(function() {
                        __obj.html(__stitle.replace('$1', Pui.space.doing.timeStamp.gettimespan(__time)));
                    },
                    400);
                }
            }
        }
    } ()
}
Pui.space.guestbook = {
    init: function() {
        Pui.space.init();
        Pui.space.emotionWR('#GuestBook');
		  Pui.space.emotionWRS('#GuestBook');
        Pui.space.commentReply('#GuestBook');
    }
}
Pui.space.other = {
    init: function() {
        Pui.space.writeMenu();
    }
}
Pui.LazyLoad={
    lazyloadThis:null,
    //初始化程序
    _initialize:function(elem)
    {
        lazyloadThis=Pui.LazyLoad;
        lazyloadThis._timer=null;//定时器
        lazyloadThis.isFinish=false;//是否完成
        lazyloadThis._lock=false,//锁住
        lazyloadThis.delay=1000;//定时间隔
        lazyloadThis.windowObj=lazyloadThis.getWindowRect();
        lazyloadThis.scrollObj=lazyloadThis.getScroll();
        lazyloadThis.containerObj=lazyloadThis.getRect(elem);
    },
    load:function(run)
    {
        if(run==null||typeof(run) != "function") return;
        $(window).scroll(function()
        {
            lazyloadThis.scrollObj=lazyloadThis.getScroll();
            if((lazyloadThis.scrollObj.top+lazyloadThis.windowObj.bottom)>lazyloadThis.containerObj.top)
            {
                lazyloadThis._delay(run);
                lazyloadThis.isFinish=true;
            } 
            return false;
        });
        $(window).scroll();
    },
    getScroll:function()
    {
        var t, l, w, h;
        if (document.documentElement && document.documentElement.scrollTop) 
        {
            t = document.documentElement.scrollTop;
            l = document.documentElement.scrollLeft;
            w = document.documentElement.scrollWidth;
            h = document.documentElement.scrollHeight;
        } 
        else if (document.body) 
        {
            t = document.body.scrollTop;
            l = document.body.scrollLeft;
            w = document.body.scrollWidth;
            h = document.body.scrollHeight;
        }
        return { "top": t, "left": l, "right": w, "bottom": h };
    }, 
    getWindowRect:function()
    {
        return ( "innerHeight" in window )?{"left":	0, "right":	window.innerWidth,"top":0, "bottom":window.innerHeight}:{"left":	0, "right":	document.documentElement.offsetWidth,"top":0, "bottom":document.documentElement.offsetHeight};
    },
    getRect:function(node) {
        var n = node, left = 0, top = 0;
        while (n) { left += n.offsetLeft; top += n.offsetTop; n = n.offsetParent; };
        return {
            "left": left, "right": left + node.offsetWidth,
            "top": top, "bottom": top + node.offsetHeight
        };
      },
    //延时程序
    _delay:function(run) {
        clearTimeout(lazyloadThis._timer);
        if ( lazyloadThis.isFinish ) return;
        var oThis = this, delay = lazyloadThis.delay;
        if ( lazyloadThis._lock ) {//防止连续触发
            lazyloadThis._timer = setTimeout( function(){ oThis._delay(run); }, delay );
        } else {
            lazyloadThis._lock = true; run();lazyloadThis.testAlert("runed");
            setTimeout( function(){ oThis._lock = false; }, delay );
        }
    },
    testAlert:function(str)
    {
        if(location.href.indexOf("localhost")>-1)
        {
            alert(str);   
        }
    }
};